/**   
 * @Title: AlertFather.java 
 * @Package com.esun.lottery.shiyixuanwu.alertviews 
 * @Description: 十一选五弹出窗口父类
 * @author Miko baoz@500wan.com   
 * @date 2011-1-15 下午04:52:31  
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk;

import java.util.ArrayList;

import com.esun.ui.R;
import com.esun.util.log.EDebug;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * @ClassName: AlertFather
 * @Description: 十一选五弹出窗口通用父类
 * @author Miko baoz@500wan.com
 * @date 2011-1-15 下午04:52:31
 * 
 */
public class AlertFather implements DialogInterface.OnDismissListener {
	public AlertFather(Context context, View view, Button tvStyle) {
		this.context = context;
//		this.tvStyle = tvStyle;
		this.view = view;
	}

	// MainAct
	private Context context;

	// View 整个Alert的View
	private View alertView;

	// 显示的AlertDialog
	private Dialog alert;

	// 右上角叉叉button
	private Button btnClose;

	// 玩法显示
//	private Button tvStyle;

	// 投注方式显示
	// private TextView tvDetail;

	// 十一选五的整个view
	private View view;

	// 玩法button
	private ArrayList<Button> alBtnStyle = new ArrayList<Button>();

	// 方式butoon
	private ArrayList<Button> alBtnDetail = new ArrayList<Button>();

	// 是否为关闭按钮
	private boolean isClose;

	// 玩法提示文字
	private TextView tvPlayTip;

	/**
	 * @Title: init
	 * @Description: 初始化该View界面
	 * @return void
	 */
	protected void init(int[] buttonID, View.OnClickListener listener, int layout) {

		tvPlayTip = (TextView) view.findViewById(R.id.shiyixuanwu_container_playTip);

		EDebug.o(this, "alert == null --> " + String.valueOf(alert == null));
		if (alert == null) {

			alertView = ((Activity) context).getLayoutInflater().inflate(layout, null);

			// 关闭按钮
			btnClose = (Button) alertView.findViewById(buttonID[0]);
			btnClose.setOnClickListener(listener);

			int mark = buttonID.length;

			EDebug.o(this, "the ID Length is : " + String.valueOf(mark));

			for (int i = 1; i < mark; i++) {
				Button btn = (Button) alertView.findViewById(buttonID[i]);
				btn.setOnClickListener(listener);
				if (mark > 4) {
					EDebug.o(this, "add Style to ArrayList");
					alBtnStyle.add(btn);
				} else {
					EDebug.o(this, "add Detail to ArrayList");
					alBtnDetail.add(btn);
				}
			}

			if (alBtnStyle.size() > 1) {
				ShiyixuanwuPlayStyle.getPlayStyle().setAlBtnStyle(alBtnStyle);
				ShiyixuanwuPlayStyle.getPlayStyle().getAlBtnStyle();
				EDebug.o(this, "now the size is : " + String.valueOf(ShiyixuanwuPlayStyle.getPlayStyle().getAlBtnStyle().size()));
			}

			if (alBtnDetail.size() > 1) {
				ShiyixuanwuPlayStyle.getPlayStyle().setAlBtnDetail(alBtnDetail);
				ShiyixuanwuPlayStyle.getPlayStyle().getAlBtnDetail();
				EDebug.o(this, "now the size is : " + String.valueOf(ShiyixuanwuPlayStyle.getPlayStyle().getAlBtnDetail().size()));
			}

			EDebug.o(this, "Building Choose Style Alert..");
			alert = new Dialog(context, R.style.dialog);
			alert.getWindow().setContentView(alertView);
			alert.setOnKeyListener(new DialogInterface.OnKeyListener() {

				@Override
				public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

					if (keyCode == KeyEvent.KEYCODE_BACK) {
						isClose = true;
						alert.dismiss();
						return true;
					}
					return false;
				}
			});
			alert.setOnDismissListener(this);
			EDebug.o(this, "Building Choose Style Alert Finish..");
		}

	}

	/**
	 * @Title: alerShow
	 * @Description: 显示Alert
	 * @return void
	 */
	protected void alerShow() {
		alert.show();
	}

	public void alertCancel(boolean close) {
		alert.dismiss();
		isClose = close;
	}

	@Override
	public void onDismiss(DialogInterface dialog) {

		if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 1) {
			tvPlayTip.setText("玩法提示：从11个号码中任选1个号码。奖金13元。");
		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 2) {
			if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 1) {
				ShiyixuanwuPlayStyle.getPlayStyle().setDetailTemp("任选二");
				tvPlayTip.setText("玩法提示：从11个号码中任选2个号码。奖金6元。");
			} else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 2) {
				ShiyixuanwuPlayStyle.getPlayStyle().setDetailTemp("前二直选");
				tvPlayTip.setText("玩法提示：每行各选1个号码。奖金130元。");
			} else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 3) {
				ShiyixuanwuPlayStyle.getPlayStyle().setDetailTemp("前二组选");
				tvPlayTip.setText("玩法提示：任意2个号码组成1注有效注。奖金65元.");
			}
		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 3) {
			if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 1) {
				ShiyixuanwuPlayStyle.getPlayStyle().setDetailTemp("任选三");
				tvPlayTip.setText("玩法提示：从11个号码中任选3个号码。奖金19元。 ");
			} else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 2) {
				ShiyixuanwuPlayStyle.getPlayStyle().setDetailTemp("前三直选");
				tvPlayTip.setText("玩法提示：每行各选1个号码。奖金1170元。");
			} else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 3) {
				ShiyixuanwuPlayStyle.getPlayStyle().setDetailTemp("前三组选");
				tvPlayTip.setText("玩法提示：任意3个号码组成1注有效注。奖金195元.");
			}
		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 4) {
			tvPlayTip.setText("玩法提示：从11个号码中任选4个号码。奖金78元。");
		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 5) {
			tvPlayTip.setText("玩法提示：从11个号码中任选5个号码。奖金540元。");
		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 6) {
			tvPlayTip.setText("玩法提示：从11个号码中任选6个号码。奖金90元。");
		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 7) {
			tvPlayTip.setText("玩法提示：从11个号码中任选7个号码。奖金26元。");
		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 8) {
			tvPlayTip.setText("玩法提示：从11个号码中任选8个号码。奖金9元。");
		}

		if (!isClose) {
			// tvStyle.setText(ShiyixuanwuPlayStyle.getPlayStyle().getStyleTxt());
			((TextView) view.findViewById(R.id.shiyixuanwu_choose_tv_playTip)).setText(ShiyixuanwuPlayStyle.getPlayStyle().getStyleTxt());

			if (!ShiyixuanwuPlayStyle.getPlayStyle().getDetailTemp().equals(DataShare.NULLMARK)) {
				// tvStyle.setText(ShiyixuanwuPlayStyle.getPlayStyle().getDetailTemp());
				((TextView) view.findViewById(R.id.shiyixuanwu_choose_tv_playTip)).setText(ShiyixuanwuPlayStyle.getPlayStyle().getDetailTemp());
			}

			new ShiyixuanwuChooseBallSpace(context, view, ShiyixuanwuPlayStyle.getPlayStyle().getStyle(), ShiyixuanwuPlayStyle.getPlayStyle().getDetail());

			// ShiyixuanwuBuyingInfo.getBuyingInfo().replaceAllData();
		}

	}
}
